function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}
$(function() {
    $("#form1").submit(function (e) {
        e.preventDefault()
        var name= $(" #name").val();
        var province = $(" #province").val();
        var city = $("#city").val();
        var district = $("#district").val();
        var site = $("#site").val();
        var postcode = $("#postcode").val();
        var mobile = $("#mobile").val();
        var telephone = $("#telephone").val();


        if (!name) {
            alert('请填写用户昵称');
            return;
        }

        if (!province) {
            alert("请填写省份");
            return;
        }

        if (!city) {
            alert("请选择市/县");
            return;
        }

        if (!district) {
            alert("请选择区/县");
            return;
        }

        if (!site) {
            alert("请填写收货地址");
            return;
        }

        if (!postcode) {
            alert("请填写邮政编码");
            return;
        }

        if (!mobile) {
            alert("请填写收件人电话");
            return;
        }

        if (!telephone) {
            alert("请填写固定电话");
            return;
        }
        var params = {
            "name": name,
            "province": province,
            "city": city,
            "district": district,
            "site": site,
            "postcode":postcode,
            "mobile":mobile,
            "telephone":telephone
        };

          $.ajax({
            url: "/user/user_address",
            type: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
        }).success(function (resp) {
            if (resp.errno == '0') {
                // window.location.href = '/User_Center';
                // alert("success")
            } else {
                alert(resp.errmsg)
            }

        }).error(function () {
            alert(resp.errmsg);
        })
    })
});